#!/usr/bin/env python
# -*-coding:utf-8-*-
# File    : liyuqi.py

import time
import smtplib
from email.header import Header
from email.mime.text import MIMEText
import logging

logging.basicConfig(
    level=logging.INFO,
    datefmt='%Y-%m-%d %H:%M:%S',
    format='%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s')


FROM_EMAIL = "xxx@qq.com"
FROM_PASSWORD = "xxxx"


def sendqqmail(title, content, receiver):

    to_list = receiver.split(',')
    sender = FROM_EMAIL
    username = FROM_EMAIL
    password = FROM_PASSWORD

    # 邮件内容, 格式, 编码
    message = MIMEText(content, 'html', 'utf-8')
    message['From'] = sender
    message['To'] = receiver
    message['Subject'] = Header(title, 'utf-8')

    try:
        conn = smtplib.SMTP_SSL('smtp.exmail.qq.com', 465)
        conn.set_debuglevel(1)
        conn.login(username, password)
        conn.sendmail(sender, to_list, message.as_string())
        conn.quit()
    except smtplib.SMTPException as e:
        logging.error("发送邮件失败")
        logging.error(e)


def main():
    while True:
        sendqqmail("打卡提醒", "打卡提醒邮件通知", "xxx@xx.com")
        time.sleep(60 * 60 * 24)
